<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/* @var $this \Magento\Wishlist\Block\Customer\Sidebar */
?>
<?php
$count = $this->getItemCount();
$wishlistHelper = $this->helper('Magento\Wishlist\Helper\Data');
?>
<?php if ($wishlistHelper->isAllow()) : ?>
    <?php $imageBlock =  $this->getLayout()->createBlock('Magento\Catalog\Block\Product\Image');?>
    <div class="block wishlist">
        <div class="title">
            <strong><?php echo $this->getTitle(); ?></strong>
            <?php if($count > 0): ?>
            <span class="counter qty"><?php echo ($count == 1) ? __('1 item') : __('%1 items',$count) ?></span>
            <?php endif; ?>
        </div>
        <div class="content">
            <strong class="subtitle"><?php echo __('Last Added Items') ?></strong>
            <?php if ($this->hasWishlistItems()): ?>
                <ol class="items minilist products" id="wishlist-sidebar">
                    <?php $iterator = 1; ?>
                    <?php foreach ($this->getWishlistItems() as $item): ?>
                        <?php $product = $item->getProduct(); ?>
                        <?php echo ($iterator++ == 1) ? '<li class="item product">' : '</li><li class="item product">' ?>
                        <div class="product">
                            <a class="product photo" href="<?php echo $this->getProductUrl($item) ?>" title="<?php echo $this->escapeHtml($product->getName()) ?>">
                                <?php echo $imageBlock->init($product, 'wishlist_sidebar_block')->toHtml() ?>
                            </a>
                            <div class="product details">
                                <strong class="product name"><a href="<?php echo $this->getProductUrl($item) ?>"><?php echo $this->escapeHtml($product->getName()) ?></a></strong>
                                <?php
                                    echo $this->getProductPriceHtml(
                                        $product,
                                        \Magento\Catalog\Pricing\Price\ConfiguredPriceInterface::CONFIGURED_PRICE_CODE,
                                        \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
                                        ['item' => $item]
                                    );
                                ?>
                                <div class="product actions">
                                    <?php if ($product->isSaleable() && $product->isVisibleInSiteVisibility()): ?>
                                        <?php if ($product->getTypeInstance()->hasRequiredOptions($product)): ?>
                                            <div class="primary"><a href="<?php echo $this->getItemAddToCartUrl($item) ?>" class="action tocart primary"><span><?php echo __('Add to Cart') ?></span></a></div>
                                        <?php else: ?>
                                            <?php
                                                $postDataHelper = $this->helper('Magento\Core\Helper\PostData');
                                                $postData = $postDataHelper->getPostData($this->getItemAddToCartUrl($item), ['product' => $product->getEntityId()])
                                            ?>
                                            <div class="primary"><button type="button" class="action tocart primary" data-post='<?php echo $postData; ?>'><span><?php echo __('Add to Cart') ?></span></button></div>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                    <div class="secondary">
                                        <a href="#" data-post='<?php echo $this->getItemRemoveParams($item) ?>' title="<?php echo __('Remove This Item') ?>" class="btn-remove action delete">
                                            <span><?php echo __('Remove This Item') ?></span>
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php echo ($iterator == count($this->getWishlistItems()) + 1) ? '</li>' : '' ?>
                    <?php endforeach; ?>
                </ol>
                <div class="actions">
                    <a class="action details" href="<?php echo $this->helper('Magento\Wishlist\Helper\Data')->getListUrl() ?>"><span><?php echo __('Go to Wish List') ?></span></a>
                </div>
            <?php else: ?>
                <p class="message info empty"><?php echo __('You have no items in your wish list.') ?></p>
            <?php endif ?>
        </div>
    </div>
<?php endif ?>
